/*
 * Created on 07.12.2012
 *
 */
package de.denniswilmsmann.jmslogger;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import javax.jms.JMSException;

import de.denniswilmsmann.jmslogger.activemq.Consumer;
import de.denniswilmsmann.jmslogger.activemq.Producer;

/*
 * $Log: $
 */

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {

        try {

            List<Consumer> consumers = new ArrayList<Consumer>();
            for (int i = 0; i < 128; i++) {
                Consumer c = new Consumer("Consumer-" + i);
                c.consumeMessage();
                consumers.add(c);
            }

            ExecutorService threadPool = Executors.newCachedThreadPool();

            for (int i = 0; i < 64; i++) {
                Producer p = new Producer("Producer " + i);
                threadPool.execute(p);
            }

            threadPool.shutdown();
            try {
                threadPool.awaitTermination(60L, TimeUnit.MINUTES);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("shutting down consumers");

            for (Consumer c : consumers) {
                c.destroy();
            }

        } catch (JMSException e) {
            e.printStackTrace();
        }

        System.out.println("finished");
    }
}
